public class practice {
    class Solution {
        public int search(int[] nums, int target) {
            if (nums == null || nums.length == 0) {
                return -1;
            }
            int left = 0, right = nums.length-1;
            while(left < right) {
                int mid = (right + left) / 2;
                if (target == nums[mid]) {
                    return mid;
                } else if (target > nums[mid]) {
                    left = mid + 1;
                } else {
                    right = right - 1;
                }
            }
            if (nums[left] == target) {
                return left;
            }
            return -1;
        }
    }
}
